<?php
/**
 * Smarty plugin
 * @category VaselinEngine
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {call_input_plugin} function plugin
 *
 * Type:     function<br>
 * Name:     call_input_plugin<br>
 * Purpose:  print form input. Type of input is defined in $params['type']
 * @author Konstantin Shamko <konstantin.shamko@gmail.com>
 * @param array parameters
 * @param Smarty
 * @return string|null
 */
function smarty_function_call_input_plugin($params, &$smarty) {
	
	unset($params['add_params']['validations'],$params['add_params']['@attributes']);
	
	if(isset($params ['add_params'] ['value'])){
		$params ['add_params'] ['value'] = htmlspecialchars( $params ['add_params'] ['value']);
	}
	/* handling missing params errors start */
	if (! isset ( $params ['name'] )) {
		$smarty->trigger_error ( "<b>FormGenerator (call_input_plugin) warning:<b/> missing 'name' parameter" );
		$error_flag = 1;
	}
	
	if (! isset ( $params ['type'] )) {
		$smarty->trigger_error ( "<b>FormGenerator (call_input_plugin) warning:<b/> missing 'type' parameter" );
		$error_flag = 1;
	}
	if ($error_flag)
		return;
		/* handling missing params errors end */
	
	//array with available standart html inputs
	$html_inputs = array ('text', 'password', 'checkbox', /*'radio',*/ 'submit', 'reset', 'hidden', 'textarea', 'image', 'button' ); //file
	

	$plugin_name = (in_array ( strtolower ( $params ['type'] ), $html_inputs )) ? 'input' : $params ['type'];
	
	$function = 'smarty_function_' . $plugin_name;
	$function_path = dirname ( __FILE__ ) . '/function.' . $plugin_name . '.php';
	
	include_once ($function_path);
	$function ( $params ['add_params'], $smarty );
}